﻿using Microsoft.AspNetCore.Builder;

namespace OData.Shared.Extensions;

public static class ApplicationBuilderExtensions
{
	public static IApplicationBuilder UseSwaggerWithUi(this WebApplication app)
	{
		app.UseSwagger();
		app.UseSwaggerUI(c =>
		{
			var descriptions = app.DescribeApiVersions();
			foreach (var description in descriptions)
			{
				var url = $"/swagger/{description.GroupName}/swagger.json";
				var name = description.GroupName.ToUpperInvariant();
				c.SwaggerEndpoint(url, name);
			}
		});
		return app;
	}
}
